package com.summer.framework.core.filter;

import com.summer.framework.base.constant.IntegerConstant;
import com.summer.framework.core.context.UserContext;
import jakarta.servlet.*;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * Description : 登录以及访问权限拦截器
 * @author Ice Yang
 * Date 2025/9/12 13:41
 */
@Component
@Order(IntegerConstant.ZERO)
public class AuthFilter implements Filter {

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) servletRequest;
        HttpServletResponse res = (HttpServletResponse) servletResponse;
        try {
            filterChain.doFilter(req,res);
        }finally {
            UserContext.clear();
        }

    }
}
